function f_check_mode_opt()
{
    declare update_state fun_name
    fun_name="f_check_mode_opt"
    update_state=0
    if [ "${mode_opt}x" == "start_taskx" ]
    then
        f_update_status_for_task_from_api "run_state = 0" "继续改表" || update_state=1
    elif [ "${mode_opt}x" == "stop_taskx" ]
    then
        f_update_status_for_task_from_api "run_state = -1" "终止改表" || update_state=1
    elif [ "${mode_opt}x" == "pause_taskx" ]
    then
        f_update_status_for_task_from_api "run_state = 1" "暂停改表" || update_state=1
    elif [ "${mode_opt}x" == "chunk_sizex" ]
    then
        f_update_status_for_task_from_api "chunk_size = ${update_number}" "修改chunk size" || update_state=1
    elif [ "${mode_opt}x" == "repl_timex" ]
    then
        f_update_status_for_task_from_api "repl_time = ${update_number}" "修改最大延迟时间" || update_state=1
    elif [ "${mode_opt}x" == "big_tablex" ]
    then
        f_update_status_for_task_from_api "big_table = 1" "修改表大小不受500GB限制" "insert" "1,0,0" || update_state=1          #1表示big_table, 0 表示disk_space
    elif [ "${mode_opt}x" == "disk_spacex" ]
    then
        f_update_status_for_task_from_api "disk_space = 1" "修改磁盘空间不受2倍表大小限制" "insert" "0,1,0" || update_state=1   #0表示big_table, 1 表示disk_space
    elif [ "${mode_opt}x" == "get_progressx" ]
    then
        f_update_status_for_task_from_api "progress" "获取改表进度" "select" "0,0,0" || update_state=1     #获取进度
    elif [ "${mode_opt}x" == "osc_toolx" ]
    then
        f_update_status_for_task_from_api "osc_tool = 1" "修改改表使用工具" "insert" "0,0,1" || update_state=1     #修改osc工具, 该端口下的所有工单都使用pt
    elif [ "${mode_opt}x" == "unique_keyx" ]
    then
        f_update_status_for_task_from_api "unique_key = 1" "修改允许添加唯一索引" && exit 0 || exit 1     #默认不允许添加唯一索引，存在风险
    else
        sql_file="${sql_file_dir}/${sql_file}"
        if [ -f "${sql_file}" ]
        then #如果不存在文件就说明是drop或者truncate动作, sql文件只是针对create|alter操作
            [ -z "${mode_opt}" ] && mode_opt="$(awk -F/ '{print $NF}' <<< "${sql_file}"|awk -F. '{print $1}')"     #判断是alter|create, 这里主要是以命令行参数优先
            mysql_db="$(awk -F/ '{print $NF}' <<< "${sql_file}"|awk -F. '{print $2}')"     #获取操作的db
            mysql_port="$(awk -F/ '{print $NF}' <<< "${sql_file}"|awk -F. '{print $3}')"   #获取端口号
            order_applytime="$(awk -F/ '{print $NF}' <<< "${sql_file}"|awk -F. '{print $4}')"   #获取工单申请时间
            order_applytime="$(date -d @${order_applytime} "+%F %H:%M:%S" 2>/dev/null)" || true
        fi
        
        _mysql_db_="\`${mysql_db}\`"    #给库名添加反引号, 防止用户的库名带中划线或者保留字
        
        if [ "${mode_opt}x" == "crontab_dropx" ]
        then
            f_logging "WARN:${fun_name}" "本次操作是处理延迟删除遗留的待删除的任务" "2"
        elif [ ! -f "${sql_file}" ] && [ -z "${clear_table_list}" ]
        then
            f_logging "ERROR:${fun_name}" "从 '${src_host}::DBA_OPER_TABLE/${sql_file}' 拉取sql文件成功, 但是文件 '${sql_file_dir}/${sql_file}' 不存在" "2" "1"
        elif [ ! -s "${sql_file}" ] && [ "$(grep -iPc "^(create|alter)_table" <<< "${mode_opt}")x" == "1x" ]
        then
            f_logging "ERROR:${fun_name}" "'${sql_file_dir}/${sql_file}' 是空文件" "2" "1"
        elif [ ! -f "${sql_file}" ]
        then
            sql_file="$(awk -F'@' '{print $1}' <<< "${user_mail_addr}")_${user_order_id}"
            f_logging "WARN:${fun_name}" "本次操作是drop|truncate table" "2"
        fi
        
        #本次操作保存的日志, 是'sql文件名.log'
        log_file="${script_execute_res_log_dir}/$(awk -F/ '{print $NF}' <<< "${sql_file}").log"
        f_logging "REMAIND:${fun_name}" "开始执行 : '${s_n} ${*}' ] [ 本次操作日志, 详情请看 : ${log_file}"
        [ -n "${src_host}" ] && f_logging "REMAIND:${fun_name}" "从 '${src_host}' 拉取sql文件保存在 '${sql_file}'"

        update_state=100
    fi
    return ${update_state}
}

function f_prepare()
{
    declare fun_name
    fun_name="f_prepare"
    if [ "$(grep -ic "^create_table" <<< "${mode_opt}")x" == "1x" ]
    then
        [ "${execute}x" == "1x" ] && test_db="${test_db_exe}"
        f_get_create_sql
    elif [ "$(grep -ic "^alter_table" <<< "${mode_opt}")x" == "1x" ]
    then
        f_get_diy_info || true
        if [ "${execute}x" == "0x" ] && [ "${ghost_to_ptosc}x" == "0x" ]
        then
            f_return_alter_sql
            f_get_alter_sql
        fi
        f_check_osc_or_alter && return ${?} || return ${?}
    elif [ "$(grep -ic "^drop_table" <<< "${mode_opt}")x" == "1x" ]
    then
        f_clear_table "drop table"
    elif [ "$(grep -ic "^later_drop_table" <<< "${mode_opt}")x" == "1x" ]
    then
        f_clear_table "rename table"
    elif [ "$(grep -ic "^truncate_table" <<< "${mode_opt}")x" == "1x" ]
    then
        f_clear_table "truncate table"
    elif [ "$(grep -ic "^later_truncate_table" <<< "${mode_opt}")x" == "1x" ]
    then
        f_clear_table "truncate table" "later"
    elif [ "$(grep -ic "^recover" <<< "${mode_opt}")x" == "1x" ]
    then
        f_clear_table "recover"
    elif [ "$(grep -ic "^crontab_drop" <<< "${mode_opt}")x" == "1x" ]
    then
        f_clear_table "crontab_drop"
    else
        f_logging "WARN:${fun_name}" "暂时不支持这种操作 '${mode_opt}'" "2" "1"
    fi
    return 0
}


